package org.example.librarysystemspringboot.service.impl;

import org.example.librarysystemspringboot.entity.model.Reader;
import org.example.librarysystemspringboot.repository.ReaderRepository;
import org.example.librarysystemspringboot.service.ReaderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ReaderServiceImpl implements ReaderService {
    @Autowired
    private ReaderRepository readerRepository;

    @Override
    public Reader addReader(Reader reader) {
        readerRepository.save(reader);
        return null;
    }

    @Override
    public Reader select(String name, String password) {
        return readerRepository.findByNameAndPassword(name,  password);
    }

    @Override
    public Boolean changePassword(String id, String newPassword) {
        Reader reader = readerRepository.findById(id);
        if (reader != null) {
            reader.setPassword(newPassword);
            readerRepository.save(reader);
            return true;
        }
        return null;
    }
}
